import { Form, Row, Col, Button, Space } from 'antd'
import { SearchOutlined, ReloadOutlined } from '@ant-design/icons'

export default function SearchForm({
    children,
    onSearch,
    onReset,
    loading = false
}) {
    const [form] = Form.useForm()

    const handleReset = () => {
        form.resetFields()
        onReset?.()
    }

    const handleSearch = async () => {
        const values = await form.validateFields()
        onSearch?.(values)
    }

    return (
        <Form
            form={form}
            layout="horizontal"
            onFinish={handleSearch}
        >
            <Row gutter={24}>
                {children}
                <Col span={24} style={{ textAlign: 'right', marginTop: 16 }}>
                    <Space>
                        <Button
                            type="primary"
                            icon={<SearchOutlined />}
                            onClick={handleSearch}
                            loading={loading}
                        >
                            搜索
                        </Button>
                        <Button
                            icon={<ReloadOutlined />}
                            onClick={handleReset}
                        >
                            重置
                        </Button>
                    </Space>
                </Col>
            </Row>
        </Form>
    )
} 